//table头信息 不变
var dm_columnData = [

    {"Width": "33%", "ColumnName": "字段"},
    {"Width": "33%", "ColumnName": "属性"},
    {"Width": "33%", "ColumnName": "操作"}
];

//操作按钮 不变
var dm_operateHtml = "<div class='form-inline'>" +
    " <button type='button' class='btn btn-primary innerButtons'  value='edit'>编辑</button>" +
    "</div>";


//用户管理分页函数
var gotoPage = function (index) {
    var url = webPath + "/crm/1";
    //TODO FORm val()
    var postData = {"pageSize": pageSize, "pageNumber": index};
    var options = {"passArguments": index}
    postAjax(url, postData, gotoPageSuccess, options);

};

var gotoPageSuccess = function (result, passArguments) {
    //TODO remove
    result = '{"totalNumber":3,"list":[{"segment":"字段","property":"属性"}]}';

    var columnList = ["segment", "property"];
    //$.post(url, postData, function (result) {
    cleanTableAndPage("dictionaryManagementTable");
    var jsonData = $.parseJSON(result);
    //画table
    $("#dictionaryManagementTable").MakeTable(false, dm_columnData, jsonData.list, tableClass, columnList, dm_operateHtml);
    //画分页
    $("#dictionaryManagementTable").after(comPagination(passArguments, pageSize, jsonData.totalNumber, "gotoPage", "dictionaryManagementP"));
    //});

    //table操作栏 编辑
    $("#dictionaryManagementTable button").click(function () {
        var that = $(this);

        var buttonType = that.val();
        if (buttonType === "edit") {
            editDictionary(that);
        } else {
            alert("sometion wrong");
        }
    });
}

var editDictionary = function (that) {
    getPage(webPath + "/crm/dictionaryMaintain/" + getDictionaryId(that) + ".do");
    //var url = webPath + "/crm/";
    //var postData = {"dictionaryId": getDictionaryId(that)};
    //postAjax(url, postData, editDictionarySuccess);
}

//var editDictionarySuccess = function(){
//    getPage(webPath + "/crm/dictionaryMaintain/"+customerId +".do"):
//}

//查询按钮行为 TODO Change
//$('#searchCRecordBtn').click(function () {
//    gotoPage(1);
//});

//获取id 方便提交 TODO Change
//var getContectRecordId = function (that) {
//    return that.closest("tr").find("td div")[1].innerHTML;
//}

//获取id 方便提交 TODO Change
var getDictionaryId = function (that) {
    return that.closest("tr").find("td div")[1].innerHTML;
}